<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../static/js/common.js"></script>
</head>
<body>
<table class="table-top" id="formArea">
	<tr>
		<td>
			<input type="text" class="input" name="complex" autocomplete="off" placeholder="请输入单位名称 或编码"/>
		</td>
		<td>
			<div class="radio-div">
				<input type="radio" value="1" name="relationType" id="type1"/>
				<label radio="radio" for="type1">供应商</label>
			</div>
			<div class="radio-div" style="margin-left:20px;">
				<input type="radio" value="2" name="relationType" id="type2"/>
				<label radio="radio" for="type2">客户</label>
			</div>
		</td>
		<td>
			<button class="button" id="query"><span>查询</span></button>
		</td>
	</tr>
</table>
<div id="table"></div>
<script>
    var params = app.getRequestParams();
    $(function(){
        function query(){
            var queryParams = app.serializeForm();
            $('#table').datagrid("reload",queryParams);
		}

        $('#query').click(query);
        $('input[name="relationType"]').click(query);

        if(parent.params.relationType){
            $('input[name="relationType"][value="'+parent.params.relationType+'"]').prop('checked',true);
		}else{
            $('input[name="relationType"][value="2"]').prop('checked',true);
		}

        $('#table').datagrid({
            url:app.BASE_API_URL+'account/payerPage',
			limit:8,limits:[8],
            simplePagination:true,
            queryParams:{relationType:$('input[name="relationType"]:checked').val()},
            columns:[
                {field:'name',title:'单位名称',width:100,formatter:function (row) {
					return '<a href="javascript:void(0);" onclick="selectRow(this)" class="link">'+row.name+'</a>';
				 }},
                {field:'code',title:'单位编码',width:100},
                {field:'contact',title:'联系人',width:80,fixed:true},
                {field:'contactPhone',title:'联系电话',width:100}
            ]
        });
    });

    function selectRow(_this) {
        var row = $(_this).parent().parent().data();
        parent.params.relationType = $('input[name="relationType"]:checked').val();
        parent.params.relationId = row.id;
        $('input[name="order.debtMoney"]',parent.document).val('0.00');
        var search = parent.$('#'+params.searchId);
        search.search('setValue',row.id,row.name);
        app.closeLastWindow();
    }

</script>
</body>
</html>